package com.zhb.lkd.controller;


import com.zhb.lkd.base.PageResponse;
import com.zhb.lkd.base.ResponseResult;
import com.zhb.lkd.exception.BusinessException;
import com.zhb.lkd.pojos.dto.SkuClassPageDto;
import com.zhb.lkd.pojos.entity.Partner;
import com.zhb.lkd.pojos.entity.Sku;
import com.zhb.lkd.pojos.entity.SkuClass;
import com.zhb.lkd.pojos.vo.PartnerVo;
import com.zhb.lkd.service.IPartnerService;
import com.zhb.lkd.service.ISkuClassService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 合作商表 前端控制器
 * </p>
 *
 * @author haibin
 * @since 2024-08-18
 */
@RestController
@RequestMapping("/api/user-service/partner")
@Slf4j
@Api(tags = "合作商管理相关接口")
public class PartnerController {
    @Resource
    private IPartnerService partnerService;

    @GetMapping("/search")
    @ApiOperation("合作商搜索")
    public ResponseResult search(
            @RequestParam(defaultValue = "1") Integer pageIndex,
            @RequestParam(defaultValue = "10") Integer pageSize,
            String name) {
        log.info("合作商搜索{}", pageIndex);
        PageResponse pageResponse = partnerService.search(pageIndex,pageSize,name);
        return ResponseResult.ok(pageResponse);
    }


    @PostMapping("")
    @ApiOperation("新增合作商")
    public ResponseResult create(@RequestBody Partner partner) {
        log.info("新增合作商{}", partner);
        partnerService.create(partner);
        return ResponseResult.ok();
    }


    @PutMapping()
    @ApiOperation("修改合作商")
    public ResponseResult updateById(@RequestBody Partner partner) {
        log.info("修改合作商{}", partner);
        if (partner.getId()==0||partner.getId()==null){
            throw new BusinessException(500,"合作商id不能为空");
        }
        boolean b = partnerService.updateById(partner);
        return ResponseResult.ok();
    }


    @DeleteMapping("/{id}")
    @ApiOperation("删除合作商")
    public ResponseResult deleteById(@PathVariable String id) {
        log.info("删除合作商{}", id);
        partnerService.deleteById(id);
        return ResponseResult.ok();
    }

    @GetMapping(":{id}")
    @ApiOperation("获取合作商详情")
    public ResponseResult findById(@PathVariable String id) {
        log.info("获取合作商详情{}", id);
        PartnerVo partnervo=  partnerService.findById(id);
        return ResponseResult.ok(partnervo);
    }
    @PutMapping("/resetPwd/{id}")
    @ApiOperation("重置密码")
    public ResponseResult resetPwd(@PathVariable String id) {
        log.info("重置密码{}", id);
     partnerService.resetPwd(id);
        return ResponseResult.ok();
    }
}
